#
# Techleak Mod
# ViSaTechleakEventManager
# 

from CvPythonExtensions import *
import CvUtil

import CvEventManager
import CvConfigParser
import sys
import PyHelpers
import CvMainInterface
import ViSaTechleak


gc = CyGlobalContext()	
objTechleak = ViSaTechleak.TechLeak()

PyPlayer = PyHelpers.PyPlayer
PyGame = PyHelpers.PyGame()

def loadConfigurationData():
        
	global g_bTechleakEnable                  # enable or disable the techleak feature?
	g_bTechleakEnable = False
	

	# loads the ViSa mod ini file
	config = CvConfigParser.CvConfigParser("ViSa-Component-Control.ini")

	# If we actually were able to open the "ViSa-Component-Control.ini" file then read in the values.
	# otherwise we'll keep the default values that were set at the top of this file.
	if(config != None):
		g_bTechleakEnable = config.getboolean("ViSa Component Control","Techleak Allowed", False)
# globals
###################################################	
class TechLeakEventManager:
	
	def __init__(self, eventManager):
		# initialize base class

		loadConfigurationData()

		eventManager.addEventHandler("BeginPlayerTurn", self.onBeginPlayerTurn)
		eventManager.addEventHandler("BeginPlayerTurn", self.onTechLeakFirst)
		eventManager.addEventHandler("EndPlayerTurn", self.onEndPlayerTurn)
		eventManager.addEventHandler("OnLoad", self.onLoadGame)

	def onLoadGame(self, argsList):
		'Called upon loading a game'
		if ( g_bTechleakEnable ):
			objTechleak.doLoadGame(argsList)

	def onBeginPlayerTurn(self, argsList):
		'Called at the beginning of a players turn'
		if ( g_bTechleakEnable ):
			objTechleak.doTechLeakByTrade(argsList)

	def onTechLeakFirst(self, argsList):
		'popup some screens and buttons are handled here'
		if ( g_bTechleakEnable ):                        
			objTechleak.doTechLeakFirst(argsList)

	def onEndPlayerTurn(self, argsList):
		'clear the bloody bools'

		if ( g_bTechleakEnable ):
			objTechleak.doTrashAll(argsList)





